﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using ET.Score.Service;
using ET.Score.Service.Dtos;
using ET.Score.Service.Enums;
using ET.Score.Service.Interfaces;
using ET.Score.SharedLibrary;
using ET.Score.SharedLibrary.Wcf;
using System.Timers;
using ET.ScoreTeacherClient.ServiceProviders;
using System.Collections.ObjectModel;
/////司机驾驶考核服务数据实时获取
namespace ET.ScoreTeacherClient.ServiceDataMonitor
{
    public class DriverServiceMonitor : HeartBeatInvoker<IDriverManageService>
    {
       
         public DriverServiceMonitor()
            : base(CreateFactory(), HeartBeatMethod)
          {
           }
         
         private static void RunContinutyTaskInf(List<RunContinutyTask> lst)
         {

         }
        // private static void OnvobcMessageReceived(List<VobcAdvInfDto> arg)
        // {
        //    var messageEvent = EnvironmentContext.TopicEventAggregator
        //           .GetTopicEvent<MessageVobcReceivedEvent>();
        //    messageEvent.Publish(arg);
        //}
        // private static void OnRuncontinutyTaskReceived(ObservableCollection<RunContinutyTask> arg)
        // {
        //    var messageEvent = EnvironmentContext.TopicEventAggregator
        //           .GetTopicEvent<RunContinutyReceivedEvent>();
        //    messageEvent.Publish(arg);
        //}
        private static bool HeartBeatMethod(IDriverManageService proxy)
        {
            List<CDriverMessageFoTeacher> messagelist = GetMessage(proxy);
            if(messagelist==null)
                return false;
            List<VobcAdvInfDto> vobclst = messagelist.Select(m => m.vobc).ToList<VobcAdvInfDto>();
            //OnvobcMessageReceived(vobclst);//更新vobc数据
            
            foreach (CDriverMessageFoTeacher item in messagelist)
            {
                switch (item.curTaskType)
                {
                    case TaskType.NoTask:
                        
                        break;
                    case TaskType.RunContinutyTask:
                        ObservableCollection<RunContinutyTask> lst = new ObservableCollection<RunContinutyTask>(messagelist.Select(m => m.runcontinutytask).ToList<RunContinutyTask>());
                          //OnRuncontinutyTaskReceived(lst);//更新计划运行任务信息
                        break;
                    case TaskType.TurnBackTask:
                        break;

                }
            }
            return true;

        }
         private static List<CDriverMessageFoTeacher> GetMessage(IDriverManageService proxy)
         {
             var message = proxy.GetMessage();
             return message;
         }
        private static ChannelFactory<IDriverManageService> CreateFactory()
        {
            var factory = new ChannelFactory<IDriverManageService>("DriverManageService");
            return factory;
        }

        
        
        
    }
}
